<template>
  <div>
    <div class="title">
      <h1>评估结果</h1>
    </div>
    <div class="content">
      <!--      waterpfl改为surplus-->
      <el-form ref="form" :model="form" label-width="200px">
        <el-col :span="8"><div class="grid-content bg-purple">药物有效成分剩余量</div></el-col>
        <br>
        <br>
        <el-form-item
          label="剩余量："
          style="width: 600px;font-size: 8ex"
          prop="surplus"
          :rules="[
            {required: true, message: '剩余量不能为空',trigger: 'blur' }
          ]"
        >
          <el-input v-model="this.endsurplus" style="width: 100%;" placeholder="请输入内容" :disabled="true">
            <template slot="append">kg/d</template>
          </el-input>
        </el-form-item>
        <el-col :span="8"><div class="grid-content bg-purple">药物三相排放量 </div></el-col>

        <br>
        <br>
        <el-form-item
          label="水相排放量："
          style="width: 600px;font-size: 8ex"
          prop="airPfl"
          :rules="[
            {required: true, message: '损失量不能为空',trigger: 'blur' }
          ]"
        >
          <el-input v-model="this.endwater" style="width: 100%;"  :disabled="true">
            <template slot="append">kg/d</template>
          </el-input>
        </el-form-item>
        <el-form-item
          label="气相排放量："
          style="width: 600px;font-size: 8ex"
          prop="airPfl"
          :rules="[
            {required: true, message: '损失量不能为空',trigger: 'blur' }
          ]"
        >
          <el-input v-model="this.endair" style="width: 100%;"  :disabled="true">
            <template slot="append">kg/d</template>
          </el-input>
        </el-form-item>
        <el-form-item
          label="固废排放量："
          style="width: 600px;font-size: 8ex"
          prop="airPfl"
          :rules="[
            {required: true, message: '损失量不能为空',trigger: 'blur' }
          ]"
        >
          <el-input v-model="this.endsoild" style="width: 100%;"  :disabled="true">
            <template slot="append">kg/d</template>
          </el-input>
        </el-form-item>

        <el-form-item
          label="环境总排放量："
          style="width: 600px;font-size: 8ex"
          prop="airPfl"
          :rules="[
            {required: true, message: '损失量不能为空',trigger: 'blur' }
          ]"
        >
          <el-input v-model="this.totalloss" style="width: 100%;" placeholder="请输入内容(0~1范围内)" :disabled="true">
            <template slot="append">kg/d</template>
          </el-input>
        </el-form-item>

      </el-form>
      <el-button v-for="(item,index) in this.evaluate.processArray" v-show="false" :key="index">{{ item.flag }}</el-button>
      <br>
      <br>
      <br>
      <el-button style="margin-top: 12px;" @click="goBack">上一步</el-button>
      <el-button style="margin-top: 12px;" @click="sendDailyEmissions">提交</el-button>

    </div>
    <div class="right">
      <h3>各步骤三相损失量:</h3>
      <br>
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in this.evaluate.processArray"
          :key="index"
          :icon="item.icon"
          :type="item.type"
          color="#0bbd87"
          :timestamp="item.loss"
        >
          {{ item.flag }}
        </el-timeline-item>

      </el-timeline>
    </div>
  </div>

</template>

<script>
import DirectUsage from './UsageParameters/DirectUsage'
import IndirectUsage from './UsageParameters/IndirectUsage'
import BaseInformation from './BaseInformation'

export default {
  name: 'DailyEmissions',
  components: {
    DirectUsage,
    IndirectUsage
  },
  data() {
    return {
      form: {
        surplus: '',
        airPfl: '',
        soilPfl: ''
      },
      waterFunctionPath: '',
      airFunctionPath: '',
      soilFunctionPath: '',
      evaluate: {},
      abc: '',
      lossArray: [],
      totalloss: '',
      surplus: [],
      endsurplus: '',
      endair: '',
      endwater: '',
      endsoild: '',
      looswater: [],
      loosair: [],
      loossoild: []
    }
  },
  watch: {
    'form.waterPfl': function() {
      this.form.surplus = parseFloat(this.form.surplus).toFixed(6)
    },
    'form.airPfl': function() {
      this.form.airPfl = parseFloat(this.form.airPfl).toFixed(6)
    },
    'form.soilPfl': function() {
      this.form.soilPfl = parseFloat(this.form.soilPfl).toFixed(6)
    }
  },
  methods: {
    goBack() {
      this.$emit('goBack')
    },
    setPfl() {
      this.evaluate = this.$store.getters.getEvaluate
      console.log('this.evaluate:', this.evaluate)
      if (this.evaluate.lilun) { // 药物理论值已知
        this.looswater[0] = 0
        this.loosair[0] = 0
        this.loossoild[0] = 0
        this.endair = 0
        this.endwater = 0
        this.endsoild = 0
        this.totalloss = 0
        this.surplus[0] = this.evaluate.lilun

        for (var i = 0; i < this.evaluate.processArray.length; i++) {
          if (this.evaluate.processArray[i].water === '' && this.evaluate.processArray[i].solid === '' && this.evaluate.processArray[i].air === '') { // 使用默认值
            console.log('药物理论值已知且使用默认值')
            // 只有第一步的损失值是用最初理论值算的
            // for (var i = 0; i < this.evaluate.processArray.length; i++) {
            console.log('this.evaluate.processArraythis.evaluate.processArraythis.evaluate.processArray', this.evaluate.processArray)
            // 剩余量
            this.surplus[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].moextract)
            this.looswater[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].waterfactor)
            this.loosair[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].airfactor)
            this.loossoild[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].solidfactor)
            // 总损失
            this.evaluate.processArray[i].sumloss = this.looswater[i + 1] * (1 - this.evaluate.waterFwcs) + this.loosair[i + 1] * (1 - this.evaluate.airFwcs) + this.loossoild[i + 1]
            this.evaluate.processArray[i].loss = '水相:' + parseFloat(this.looswater[i + 1]).toFixed(2) + '. 气相:' + parseFloat(this.loosair[i + 1]).toFixed(2) + '. 固废:' + parseFloat(this.loossoild[i + 1]).toFixed(2)
            // this.totalloss = this.totalloss + this.evaluate.processArray[i].sumloss
            this.totalloss = (parseFloat(this.totalloss) + parseFloat(this.evaluate.processArray[i].sumloss)).toFixed(2)
            this.endair = (parseFloat(this.loosair[i + 1]) + parseFloat(this.endair)).toFixed(2)
            this.endwater = (parseFloat(this.looswater[i + 1]) + parseFloat(this.endwater)).toFixed(2)
            this.endsoild = (parseFloat(this.loossoild[i + 1]) + parseFloat(this.endsoild)).toFixed(2)
            console.log('soild剩余量', this.loossoild[i])
            console.log('sumloss', this.evaluate.processArray[i].sumloss)
            console.log('surplus剩余量', this.surplus[i + 1])
          } else {
            console.log('药物理论值已知且企业数据已知')
            // 剩余量
            this.surplus[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].extract)
            this.looswater[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].water)
            this.loosair[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].air)
            this.loossoild[i + 1] = this.surplus[i] * parseFloat(this.evaluate.processArray[i].solid)
            // 总损失
            this.evaluate.processArray[i].sumloss = this.looswater[i + 1] * (1 - this.evaluate.waterFwcs) + this.loosair[i + 1] * (1 - this.evaluate.airFwcs) + this.loossoild[i + 1]
            this.evaluate.processArray[i].loss = '水相:' + parseFloat(this.looswater[i + 1]).toFixed(2) + '. 气相:' + parseFloat(this.loosair[i + 1]).toFixed(2) + '. 固废:' + parseFloat(this.loossoild[i + 1]).toFixed(2)
            this.totalloss = (parseFloat(this.totalloss) + parseFloat(this.evaluate.processArray[i].sumloss)).toFixed(2)
            this.endair = (parseFloat(this.loosair[i + 1]) + parseFloat(this.endair)).toFixed(2)
            this.endwater = (parseFloat(this.looswater[i + 1]) + parseFloat(this.endwater)).toFixed(2)
            this.endsoild = (parseFloat(this.loossoild[i + 1]) + parseFloat(this.endsoild)).toFixed(2)
          }
        }
        // eslint-disable-next-line no-self-assign
        this.endair = (this.endair * (1 - this.evaluate.airFwcs))
        this.endwater = this.endwater * (1 - this.evaluate.waterFwcs)
        this.endsurplus = parseFloat(this.surplus[this.surplus.length - 1]).toFixed(2)
      }
    },
    finish() {
      this.$router.push("/home")
    },
    sendDailyEmissions() {
      // if (this.form.surplus != '') {
      //   if (this.form.airPfl != '') {
      //     if (this.form.soilPfl != '') {
      //       // let flag = {flag: '1'};
      const dailyEmissions = {
        endsurplus: this.form.endsurplus,
        airPfl: this.form.airPfl,
        soilPfl: this.form.soilPfl,
        waterFunctionPath: this.waterFunctionPath,
        airFunctionPath: this.airFunctionPath,
        soilFunctionPath: this.soilFunctionPath
      }
      this.$store.commit('setDailyEmissions', dailyEmissions)
      this.$emit('listenChild')
      //       } else {
      //         this.$message('废渣排放量不能为空')
      //       }
      //     } else {
      //       this.$message('废气排放量不能为空')
      //     }
      //   } else {
      //     this.$message('废水排放量不能为空')
      //   }
    }
  }
}
</script>

<style scoped lang="scss">
  .title{
    position:absolute;
    left:0px;
  }
  .content{
    position:absolute;
    top:100px;
    left:20%;
    right:25%;
    .font{
      font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif;

    }
  }
  .right {
    position: relative;
    float: right;
    top: 50px;
    right: -7%;
  }
  .el-timeline-item {
    //min-width: 380px;
    //margin-right: 20px;
    transition: all .5s;
  }
  .el-timeline-item:hover{
    margin-top: -5px;
  }
  .el-card:hover {

  }
</style>

